/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine - graphics/scene
// Copyright (c) 2015.  All Rights Reserved
//
// File:		AERenderCollection.inl
// Author:		Gianluca Belardelli
// Date:		02/04/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AERENDERCOLLECTION_INL_
#define _AERENDERCOLLECTION_INL_

AE_FORCEINLINE AEUINT32 AERenderCollection::GetNumEntries( void ) const
{
	return m_uiNumEntries;
}

AE_FORCEINLINE AEBOOL32 AERenderCollection::IsEmpty( void ) const
{
	return m_uiNumEntries == 0;
}

AE_FORCEINLINE void *AERenderCollection::GetEntry( AEUINT32 uiIndex ) const
{
	AEASSERT( uiIndex < m_uiSize );
	AEASSERT( m_arrEntries[uiIndex] ); ///< 0 resp NULL pointers are not allowed!
	return m_arrEntries[ uiIndex ];
}

AE_FORCEINLINE void AERenderCollection::AppendEntry( void *lpValue )
{
	AEASSERT( lpValue ); ///< 0 resp NULL pointers are not allowed!

	AEUINT32 uiSizeAdd = m_uiNumEntries/4;
	
	if( uiSizeAdd < m_uiMemGranularity )
		uiSizeAdd = m_uiMemGranularity;

	if( m_uiNumEntries >= m_uiSize )
		Resize( m_uiSize + uiSizeAdd ); 
	
	m_arrEntries.PushBack( lpValue );
	m_uiNumEntries++;
}

AE_FORCEINLINE void AERenderCollection::AppendEntryFast( void *lpValue )
{
	AEASSERT( m_uiNumEntries < m_uiSize );
	AEASSERT( lpValue ); ///< 0 resp NULL pointers are not allowed!
	m_arrEntries[m_uiNumEntries++] = lpValue;
}

AE_FORCEINLINE void AERenderCollection::AppendEntryUnique( void *lpValue )
{
	if( !Contains(lpValue) )
		AppendEntry(lpValue);
}

AE_FORCEINLINE AEBOOL32 AERenderCollection::Contains( const void *lpElement ) const
{
	return GetIndexOf( lpElement )>=0;
}

AE_FORCEINLINE void AERenderCollection::SetGranularity( AEUINT32 uiGranularity )
{
	AEASSERT( uiGranularity > 0 );
	m_uiMemGranularity = uiGranularity;
}

AE_FORCEINLINE AEUINT32 AERenderCollection::GetGranularity( void ) const
{
	return m_uiMemGranularity;
}

AE_FORCEINLINE void AERenderCollection::EnsureSize( AEUINT32 uiMinSize )
{
	if( uiMinSize<=m_uiSize )
		return;
	
	Resize( uiMinSize );
}

AE_FORCEINLINE void AERenderCollection::Clear( void )
{
	m_uiNumEntries = 0;
	m_arrEntries.Clear();
}

AE_FORCEINLINE AERenderCollection &AERenderCollection::operator = ( const AERenderCollection &other )
{
	return *this;
}

AE_FORCEINLINE AERenderCollection::AERenderCollection( const AERenderCollection &other )
{
}
#endif // _AERENDERCOLLECTION_INL_
